#include "LoginReply.h"

/*
<?xml version="1.0" encoding="UTF-8"?>
<Result>
	<ResultInfo resultcode="200" errormessage="OK"/>
	<Service business="AAS" function="authenticate"/>
	<ResultData querytype="Other">
		<AuthenticateResult token="" mcflag="" rank="" name="" user_domain="" phone="" 
			email="" mapservice=" " maptype="1" 
			streamtype="" protocol_type="" streamnum="" enableSendMMS="">
			<DomainList>
				<Domain domain="" cpip="" cpport="" cpsip="" assip="" essip=""/>
			</DomainList>
		</AuthenticateResult>
	</ResultData>
</Result>
*/
UserLoginRep::UserLoginRep():status(200),token("12345678"),mcflag("001"),
	rank("10"),mapservice("http://www.google.com"),maptype(2),user_domain("test150")
{
}
LoginRepReader::LoginRepReader(void)
{
}


LoginRepReader::~LoginRepReader(void)
{
}

int LoginRepReader::read(CommReply& userLogin)
{

	return 0;
}



LoginRepWriter::LoginRepWriter(void)
{
}


LoginRepWriter::~LoginRepWriter(void)
{
}
int LoginRepWriter::doWrite(const CommReply& rep,string& reply)
{
	const UserLoginRep& userRep = static_cast<const UserLoginRep&>(rep);

	TiXmlElement ResultInfoEle("ResultInfo");
	ResultInfoEle.SetAttribute("resultcode",userRep.status);
	ResultInfoEle.SetAttribute("errormessage","OK");

	m_pRootNode->InsertEndChild(ResultInfoEle);

	TiXmlElement ServiceEle("Service");
	ServiceEle.SetAttribute("business","AAS");
	ServiceEle.SetAttribute("function","authenticate");

	m_pRootNode->InsertEndChild(ServiceEle);

	TiXmlElement ResultDataEle("ResultData");
	ResultDataEle.SetAttribute("querytype","Other");

	TiXmlNode* pResultDataNode = m_pRootNode->InsertEndChild(ResultDataEle);

	TiXmlElement AuthenticateEle("AuthenticateResult");
	AuthenticateEle.SetAttribute("mcflag",userRep.mcflag);
	AuthenticateEle.SetAttribute("maptype",userRep.maptype);
	AuthenticateEle.SetAttribute("mapservice",userRep.mapservice);
	AuthenticateEle.SetAttribute("user_domain",userRep.user_domain);

	TiXmlNode* pAuthNode = pResultDataNode->InsertEndChild(AuthenticateEle);

	TiXmlElement DomainListEle("DomainList");
	TiXmlNode* pDomainListNode = pAuthNode->InsertEndChild(DomainListEle);
	int size = userRep.vecDomain.size();
	for (int i=0;i<size;i++)
	{
		TiXmlElement DomainEle("Domain");
		DomainEle.SetAttribute("domain",userRep.vecDomain[i].name);
		DomainEle.SetAttribute("cpip",userRep.vecDomain[i].ip);
		DomainEle.SetAttribute("cpport",userRep.vecDomain[i].port);
		DomainEle.SetAttribute("cpsip",userRep.vecDomain[i].sip);
		DomainEle.SetAttribute("assip",userRep.vecDomain[i].asip);
		DomainEle.SetAttribute("essip",userRep.vecDomain[i].esip);
		pDomainListNode->InsertEndChild(DomainEle);
	}
	reply << *m_pDoc;

	return 0;
}
